#include "cpu/exec/template-start.h"

#define instr xchg

static void do_execute () {
	DATA_TYPE temp = op_src->val;		//保存源操作数值
	OPERAND_W(op_src, op_dest->val);	//将目标操作数值写入源操作数
	OPERAND_W(op_dest, temp);			//将保存的源操作数值写入目标操作数
	print_asm_template2();
}

#if DATA_BYTE == 2 || DATA_BYTE == 4
//处理累加器与寄存器交换的helper函数
make_helper(concat(xchg_a2r_, SUFFIX)) {
	concat(decode_r_, SUFFIX)(eip);		//解码寄存器操作数
	op_dest->type = OP_TYPE_REG;		//设置目标操作数类型为寄存器
	op_dest->reg = R_EAX;				//指定目标寄存器为R_EAX
	op_dest->val = REG(R_EAX);			//获取R_EAX值
	snprintf(op_dest->str, OP_STR_SIZE, "%s", REG_NAME(R_EAX));		//格式化寄存器名称
	do_execute();		//交换操作
	return 1;
}
#endif
//寄存器到内存交换的helper函数
make_instr_helper(r2rm);

#include "cpu/exec/template-end.h"
